package org.example.codeservce.handler;

import org.example.codeservce.comm.Q;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Objects;

@RestControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Q exception(Exception e) {
        String message = e.getMessage();
        e.printStackTrace();
        if(Objects.nonNull(message)) {
            return Q.error().put("message", message);
        } else {
            return Q.error().put("message", "系统繁忙，请稍后重试");
        }
    }
}
